package com.sam.security;

import java.util.List;

import org.apache.struts2.config.ParentPackage;

import com.sam.core.BaseAction;
import com.sam.security.domain.Permission;
import com.sam.security.domain.Resource;
import com.sam.security.service.SecurityService;

/**
 * @project EMan
 * @author Sam
 * @version
 * @date Feb 9, 2009 3:07:27 PM
 */
@ParentPackage("default")
public class PermissionAction extends BaseAction {

	//
	private static final long serialVersionUID = 1L;
	private SecurityService securityService;
	private String permissionId;
	private Permission permission;

	public String getPermissionId() {
		return permissionId;
	}

	public SecurityService getSecurityService() {
		return securityService;
	}

	public String queryPermissionResource() {
		List<Resource> res = securityService
				.queryPermissionResource(permissionId);
		sendJSON(res.size(), res);
		return "json";
	}

	public String queryUncheckedPermissionResource() {
		List<Resource> res = securityService.queryUncheckedResource(
				permissionId, query);
		sendJSON(res.size(), res);
		return "json";
	}

	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}

	public void setSecurityService(SecurityService securityService) {
		this.securityService = securityService;
	}

	public String updatePermissionResource() {
		String[] res = dataString.split(",");
		securityService.updatePermissionResource(permissionId, res);
		sendJSON(true);
		return "json";
	}
	public String load() {
		Permission per = securityService.queryPermissionInfo(permissionId);
		sendJSON(1,per);
		return "json";
	}
	public String updatePermission() {
		securityService.updatePermission(permission);
		sendJSON(true);
		return "json";
	}
	public String delete(){
		securityService.deletePermission(dataString);
		sendJSON(true);
		return "json";
	}
	public Permission getPermission() {
		return permission;
	}

	public void setPermission(Permission permission) {
		this.permission = permission;
	}
}
